﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Patent.DBUtility;

namespace Patent
{
    /// <summary>
    /// TRSSQL 的摘要说明
    /// </summary>
    public class TRSSQL
    {
        private SQLHelper helper;

        public TRSSQL()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //

            helper = new SQLHelper(ConfigurationManager.ConnectionStrings["TRSConnectionString"].ConnectionString);
        }

        public SqlDataReader ExecuteReader(string table, string command)
        {
            string sqlString = "select * from  "+table+" where "+command;
            SqlDataReader reader;
            helper.RunSQL(sqlString,out reader);
            return reader;
        }

        public int GetTotalCount(string table, string command)
        {
            string sqlString = "select count(1) from " + table + " where " + command;
            int total=0;
            SqlDataReader reader;
            helper.RunSQL(sqlString, out reader);
            if (reader.Read())
            {
                total = reader.IsDBNull(0) ? 0 : Convert.ToInt32(reader.GetValue(0));
            }
            reader.Close();
            return total;
        }
    }
}